<template>
    <div>
        <van-nav-bar title="搜索" left-text="返回" left-arrow @click-left="back" />
    </div>
    <div>
        <div class="search">
            <form action="/">
                <van-search v-model="value" show-action placeholder="请输入搜索关键词" @search="onSearch" @cancel="onCancel" />
            </form>
        </div>
    </div>

    <!-- 内容组件 -->
    <div class="products">
        <!-- 商品 -->
        <div class="products-card" v-for="(item, index) in order1">
            <div class="img-box" @click="getProcq(item.pid, index)">
                <img :src="item.largeImg" alt="" style="border-radius: 5px; height: 100%;width: 100%;margin-top: 5px;" />
            </div>
            <div class="info1">

                <div class="name one_text">{{ item.name }}</div>
                <div class="enname one_text">{{ item.enname }}</div>
                <div class="price">￥{{ item.price }}</div>

            </div>
        </div>
    </div>
</template>

<script>
import { useRouter } from 'vue-router'
import { get } from "../request";
import { ref } from "vue";
import { showToast } from 'vant';

export default {
    setup() {

        const value = ref('');
        const onSearch = (val) => showToast(val);
        const onCancel = () => showToast('取消');

        //存放商品
        const order1 = ref([])
        const search1 = async () => {
            const res = await get("/search", {
                params: {
                    name,
                    tokenString: JSON.parse(localStorage.getItem('tokens'))
                }
            })
            order1.value = res.data.result
            console.log("商品收藏信息", res);
        }
        search1()

        //点击进入商品详情页
        const getProcq = (e) => {
            //console.log("e", e);
            router.push({ name: "Detail", query: { id: e } })
        }


        const router = useRouter();
        //返回
        const back = () => {
            router.go(-1);
        }
        return {
            back,
            getProcq,
            order1,
            search1,
            value,
            onSearch,
            onCancel,

        }
    }
}

</script>
<style lang="less" scoped>
.products {
    display: flex;
    justify-content: space-around;
    align-items: center;
    flex-wrap: wrap;
}

.products-card {
    position: relative;
    width: calc(100% / 3 - 10px);
    margin: 5px;
    border-radius: 10px;

    background-color: #ffffff;
    height: 150px;
}

.name one_text {
    font-size: 16px;
    font-weight: 700;
    margin: 2px;
}

.enname one_text {
    font-size: 10px;
    color: #acacac;
    margin: 5px 10px;
}

.price {
    font-size: 16px;
    font-weight: 700;
    margin-bottom: 10px;
    color: #182078;
    margin-top: 5px;
    float: left;
}
</style>